import { createRouter, createWebHistory } from "vue-router";
import Login from "@/views/Login.vue";
import routerGuard from './guard'

const routes = [
  { 
    path: "/", 
    name: "Home", 
    component: () => import('@/views/subject/index.vue'),
    beforeEnter: (to:any, from:any, next:any) => {
      console.log('Trying to access Index route');
      next();
    }
  },
  { 
    path: "/index", 
    name: "Index", 
    component: () => import('@/views/subject/index.vue'),
    beforeEnter: (to:any, from:any, next:any) => {
      console.log('Trying to access Index route');
      next();
    }
  },
  { 
    path: "/resource", 
    name: "Resource", 
    component: () => import('@/views/resource/resource.vue'),
    beforeEnter: (to:any, from:any, next:any) => {
      console.log('Trying to access resource route');
      next();
    }
  },
  { 
    path: "/subject", 
    name: "Subject", 
    component: () => import('@/views/subject/index.vue'),
    beforeEnter: (to:any, from:any, next:any) => {
      console.log('Trying to access Subject route');
      next();
    }
  },
  { 
    path: "/subject/config", 
    name: "SubjectConfig", 
    component: () => import('@/views/subject/config.vue'),
    beforeEnter: (to:any, from:any, next:any) => {
      console.log('Trying to access Subject config route');
      next();
    }
  },
  { 
    path: "/assistant", 
    name: "Assistant", 
    component: () => import('@/views/assistant/assistant.vue'),
    beforeEnter: (to:any, from:any, next:any) => {
      console.log('Trying to access assistant route');
      next();
    }
  },
  { 
    path: "/assistant/config", 
    name: "AssistantConfig", 
    component: () => import('@/views/assistant/config.vue'),
    beforeEnter: (to:any, from:any, next:any) => {
      console.log('Trying to access assistant config route');
      next();
    }
  },
  { 
    path: "/virtman", 
    name: "Virtman", 
    component: () => import('@/views/virtman/virtman.vue'),
    beforeEnter: (to:any, from:any, next:any) => {
      console.log('Trying to access virtman route');
      next();
    }
  },
  { 
    path: "/virtman/config", 
    name: "VirtmanConfig", 
    component: () => import('@/views/virtman/config.vue'),
    beforeEnter: (to:any, from:any, next:any) => {
      console.log('Trying to access virtman config route');
      next();
    }
  },
  { 
    path: "/granary", 
    name: "Granary", 
    component: () => import('@/views/granary/granary.vue'),
    beforeEnter: (to:any, from:any, next:any) => {
      console.log('Trying to access granary route');
      next();
    }
  },
  { 
    path: "/granary/config", 
    name: "GranaryConfig", 
    component: () => import('@/views/granary/config.vue'),
    beforeEnter: (to:any, from:any, next:any) => {
      console.log('Trying to access granary config route');
      next();
    },
    children: [
      {
        path: 'basic',
        component: () => import('@/views/granary/basic.vue'),
        beforeEnter: (to:any, from:any, next:any) => {
          console.log('Trying to access granary basic route');
          next();
        },
      },
      {
        path: 'datasource',
        component: () => import('@/views/granary/datasource.vue'),
        beforeEnter: (to:any, from:any, next:any) => {
          console.log('Trying to access granary datasource route');
          next();
        },
      },
      {
        path: 'chat',
        component: () => import('@/views/granary/chat.vue'),
        beforeEnter: (to:any, from:any, next:any) => {
          console.log('Trying to access granary datasource route');
          next();
        },
      }
    ]
  },
  { 
    path: "/setting", 
    name: "Setting", 
    component: () => import('@/views/settings/setting.vue'),
    beforeEnter: (to:any, from:any, next:any) => {
      console.log('Trying to access setting route');
      next();
    },
    children: [
      {
        path: 'member',
        component: () => import('@/views/settings/member.vue'),
        beforeEnter: (to:any, from:any, next:any) => {
          console.log('Trying to access member route');
          next();
        },
      },
      {
        path: 'llm',
        component: () => import('@/views/settings/llm.vue'),
        beforeEnter: (to:any, from:any, next:any) => {
          console.log('Trying to access llm route');
          next();
        },
      },
      {
        path: 'language',
        component: () => import('@/views/settings/language.vue'),
        beforeEnter: (to:any, from:any, next:any) => {
          console.log('Trying to access language route');
          next();
        },
      }
    ]
  },
  { 
    path: "/topic", 
    name: "Topic", 
    component: () => import('@/views/subject/topic.vue'),
    beforeEnter: (to:any, from:any, next:any) => {
      console.log('Trying to access Topic route');
      next();
    }
  },
  { 
    path: "/say", 
    name: "Say", 
    component: () => import('@/views/subject/say.vue'),
    beforeEnter: (to:any, from:any, next:any) => {
      console.log('Trying to access Say route');
      next();
    }
  },
  { 
    path: "/chat", 
    name: "Chat", 
    component: () => import('@/views/chat/chat.vue'),
    beforeEnter: (to:any, from:any, next:any) => {
      console.log('Trying to access Say route');
      next();
    }
  },
  { 
    path: "/signin", 
    name: "Signin", 
    component: () => import('@/views/sign/signin.vue'),
    beforeEnter: (to:any, from:any, next:any) => {
      console.log('Trying to access Singin route');
      next();
    }
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
  scrollBehavior: () => ({ left: 0, top: 0 })
})

// 守卫
// routerGuard(router)

// router.beforeEach((to, from, next) => {
//   console.log('Navigation to:', to.path);
//   next();
// })

export default router;